package cn.qianyan.service.Impl;

import cn.qianyan.dao.HomeDao;
import cn.qianyan.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author:
 * @createDate:
 * @description:
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private HomeDao homeDao;

    @Override
    public int countAlert() {//查询有报警数  包括警告和危险
        int alrertNum =  homeDao.countAlert();
        return alrertNum;
    }

    @Override
    public int countNormal() {//查询正常的设备数
        int Normal = homeDao.countNormal();
        return Normal;
    }

    @Override
    public List<Map> AllDevAlertNum() {//查询各已维护的设备的曾经报警数
        List<Map> DevAlertNumList = homeDao.AllDevAlertNum();
        return DevAlertNumList;
    }

    @Override
    public List<Integer> selectAlertNumByMonth() {//查询关于月份的报警数
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        List<Date> ANBMListToDate = null;
        List<String> ANBMList = homeDao.selectAlertNumByMonth();
        List<Integer> ANBMListToDate = new ArrayList<>();
        for (int i=0;i<ANBMList.size();i++){//提取月份，并转为整型
            int month =Integer.parseInt(ANBMList.get(i).substring(5,7));
            System.out.println(month);
            ANBMListToDate.add(month);
        }
        return ANBMListToDate;
    }

    @Override
    public List<Map<Object, Object>> AlertNumByRegion() {//查询各个区域的报警数
        List<Map<Object,Object>> AlertNumRegionList = homeDao.AlertNumByRegion();
        return AlertNumRegionList;
    }
}
